﻿Imports OpenDelib.ServiceDeliberations

Public Class ListeAssemblees
    Inherits ListeDossiersPage(Of ServiceDeliberations.Assemblee)

    Public Overrides ReadOnly Property Titre As String
        Get
            Return "Liste des assemblées"
        End Get
    End Property
    Protected Overrides ReadOnly Property TypeDelib As TypeDeliberation
        Get
            Return TypeDeliberation.Assemblee
        End Get
    End Property
    Protected Overrides ReadOnly Property LibelleDossier As String
        Get
            Return "assemblée"
        End Get
    End Property
    Protected Overrides ReadOnly Property LibelleFeminin As Boolean
        Get
            Return True
        End Get
    End Property
    Protected Overrides ReadOnly Property UrlFicheDossier As String
        Get
            Return "~/Assemblee/FicheAssemblee.aspx"
        End Get
    End Property
    Protected Overrides ReadOnly Property HiddenFieldIndexTabs As HiddenField
        Get
            Return Me.hfIndexTabs
        End Get
    End Property
    Protected Overrides ReadOnly Property BoutonActualiser As Button
        Get
            Return Me.btnActualiser
        End Get
    End Property
    Protected Overrides ReadOnly Property BoutonAjouterDossier As Button
        Get
            Return Me.btnAjouterDossier
        End Get
    End Property
    Protected Overrides ReadOnly Property DivTabs As HtmlGenericControl
        Get
            Return Me.tabs
        End Get
    End Property
    Protected Overrides ReadOnly Property GridViewsFields As List(Of GridViewBoundField)
        Get
            Dim fields As New List(Of GridViewBoundField)
            fields.Add(New GridViewBoundField("CodeDossier", "Code", , , HorizontalAlign.Center))
            fields.Add(New GridViewBoundField("Identificateur", "Identificateur"))
            fields.Add(New GridViewBoundField("DateAssemblee", "Date de l'assemblée", "{0:d}", , HorizontalAlign.Center))
            fields.Add(New GridViewBoundField("LieuAssemblee", "Lieu de l'assemblée", , , HorizontalAlign.Center))
            Return fields
        End Get
    End Property


    Protected Overrides Function Search(svc As DeliberationsClient, params As ParametresListe) As ResultatListeDossiersDeliberation
        Return New ResultatListeDossiersDeliberation(svc.ListeAssemblees(params))
    End Function



    'Inherits OpenDelibPage

    'Public Const TYPE_DOSSIER As String = "ASSEMB"

    'Public ReadOnly Property ListeEtats As ServiceParametre.OIItemListResult
    '    Get
    '        Return CType(ViewState("liste_etats"), ServiceParametre.OIItemListResult)
    '    End Get
    'End Property
    'Public ReadOnly Property ListeAssistants As ServiceAssistant.OIItemListResult
    '    Get
    '        Return CType(ViewState("liste_assistants"), ServiceAssistant.OIItemListResult)
    '    End Get
    'End Property
    'Public ReadOnly Property ListesDossiers As Dictionary(Of String, ServiceDeliberations.ResultatListeRapports)
    '    Get
    '        If Session("listes_dossiers_" & Tools.GetInstance.getToken) Is Nothing Then Session("listes_dossiers_" & Tools.GetInstance.getToken) = New Dictionary(Of String, ServiceDeliberations.ResultatListeRapports)
    '        Return CType(Session("listes_dossiers_" & Tools.GetInstance.getToken), Global.System.Collections.Generic.Dictionary(Of String, ServiceDeliberations.ResultatListeRapports))
    '    End Get
    'End Property



    'Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    '    Master.Titre = "Liste des assemblées"

    '    If Not IsPostBack Then
    '        ' Chargement de la liste des états de dossier associés au type de dossier
    '        Using svc As New ServiceParametre.ParametresClient
    '            Dim params As New ServiceParametre.ListeParametreParameters
    '            params.Authentication = New ServiceParametre.AuthenticationParameters
    '            params.Authentication.Token = Tools.GetInstance.getToken
    '            params.EntiteParametrage = 25
    '            params.Param1 = TYPE_DOSSIER

    '            Try
    '                ViewState("liste_etats") = svc.ListeParametre(params)
    '            Catch ex As Exception
    '                ViewState("liste_etats") = Nothing
    '                NotifyErreur(ex.Message)
    '            End Try
    '        End Using

    '        ' Chargement de la liste des assistants associés au type de dossier
    '        Using svc As New ServiceAssistant.AssistantsClient
    '            Dim params As New ServiceAssistant.ListeDeclencheursAssistantParameters
    '            params.Authentication = New ServiceAssistant.AuthenticationParameters
    '            params.Authentication.Token = Tools.GetInstance.getToken
    '            params.TypeAssistant = 6
    '            params.TypeDeclencheur = 4
    '            params.TypeEvenement = 99
    '            params.CodeParametre = TYPE_DOSSIER
    '            params.CodeParametre2 = ""

    '            Try
    '                ViewState("liste_assistants") = svc.ListeAssistantsSelonParametreEtDeclencheur(params)
    '            Catch ex As Exception
    '                ViewState("liste_assistants") = Nothing
    '                NotifyErreur(ex.Message)
    '            End Try
    '        End Using
    '    End If

    '    ' Chargement des onglets
    '    InitializeTabs()

    '    If Not IsPostBack Then
    '        Me.hfIndexTabs.Value = "0"
    '        ' Chargement des listes de dossiers selon leur état
    '        Search()
    '    End If

    '    ' Chargement des listes
    '    InitializeGridViews()
    'End Sub

    'Private Sub btnActualiser_Click(sender As Object, e As EventArgs) Handles btnActualiser.Click
    '    Search()
    '    InitializeGridViews()
    'End Sub

    'Private Sub btnAjouterAssemblee_Click(sender As Object, e As EventArgs) Handles btnAjouterDossier.Click
    '    Response.Redirect("~/Assemblee/FicheAssemblee.aspx?modeFiche=0")
    'End Sub

    'Private Sub gvDossier_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs)
    '    Dim codeDossier As String = ""

    '    Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
    '    codeDossier = CType(row.Cells(row.Cells.Count - 1).Controls(0), Label).Text

    '    Select Case e.CommandName.ToUpper
    '        Case "MODIFIER"
    '            Response.Redirect("~/Assemblee/FicheAssemblee.aspx?modeFiche=1&codeDossier=" & codeDossier)

    '        Case "SUPPRIMER"
    '            Using svc As New ServiceDossiers.DossiersClient
    '                Dim params As New ServiceDossiers.ParametresSuppressionDossier
    '                params.Authentication = New ServiceDossiers.AuthenticationParameters
    '                params.Authentication.Token = Tools.GetInstance.getToken
    '                params.Code = codeDossier
    '                params.SuppressionTotale = True

    '                Try
    '                    Dim results As ServiceDossiers.OperationResult
    '                    results = svc.Suppression(params)
    '                    If results.OK Then
    '                        NotifySuccess("Suppression effectuée avec succès.")
    '                        Search()
    '                        InitializeGridViews()
    '                    Else
    '                        NotifyErreur(results.ErrorMessage)
    '                    End If
    '                Catch ex As Exception
    '                    NotifyErreur(ex.Message)
    '                End Try
    '            End Using

    '        Case "ASSISTANT"
    '            Dim codeAss As String = CStr(e.CommandArgument)
    '            Using svc As New ServiceAssistant.AssistantsClient
    '                Dim params As New ServiceAssistant.AssistantParameters
    '                params.Authentication = New ServiceAssistant.AuthenticationParameters
    '                params.Authentication.Token = Tools.GetInstance.getToken
    '                params.CleEntite = codeDossier
    '                params.CodeAssistant = codeAss

    '                Try
    '                    Dim results As ServiceAssistant.OperationResult
    '                    results = svc.LancerAssistant(params)
    '                    If results.OK Then
    '                        NotifySuccess("Opération effectuée avec succès.")
    '                        Search()
    '                        InitializeGridViews()
    '                    Else
    '                        NotifyErreur(results.ErrorMessage)
    '                    End If
    '                Catch ex As Exception
    '                    NotifyErreur(ex.Message)
    '                End Try
    '            End Using

    '    End Select
    'End Sub



    'Private Sub InitializeTabs()
    '    ' Cette fonction permet de créer un onglet par état de dossier associé au type de dossier

    '    ' Mise à blanc des onglets
    '    Me.tabs.Controls.Clear()

    '    ' Prise en charge des erreurs de lecture des états de dossiers, ou si aucun état de dossier n'a été associé au type de dossier
    '    If ListeEtats Is Nothing OrElse Not ListeEtats.OK Then
    '        Me.tabs.InnerText = "Impossible de charger les états de dossier associés au type de dossier '" & TYPE_DOSSIER & "'" & If(ListeEtats IsNot Nothing, " :" & ControlChars.NewLine & ListeEtats.ErrorMessage, ".")
    '        Return
    '    ElseIf ListeEtats.Liste.Count <= 0 Then
    '        Me.tabs.InnerText = "Aucun état de dossier n'est associé au type de dossier '" & TYPE_DOSSIER & "'."
    '        Return
    '    Else
    '        Dim ul As New HtmlGenericControl("ul")
    '        Me.tabs.Controls.Add(ul)
    '    End If

    '    ' Ajout des onglets
    '    For Each item As ServiceParametre.OIItem In ListeEtats.Liste
    '        AddTab(item.Code, item.Libelle)
    '    Next
    'End Sub
    'Private Sub AddTab(code As String, text As String)
    '    Dim div As HtmlControls.HtmlControl
    '    Dim li As HtmlControls.HtmlControl
    '    Dim a As HtmlControls.HtmlAnchor
    '    Dim gv As GridView
    '    Dim id As String

    '    id = "tb" & code

    '    ' Ajout du contenu de l'onglet
    '    div = New HtmlGenericControl("div")
    '    div.ID = id

    '    ' Création du datagrid
    '    gv = New GridView()
    '    gv.AllowPaging = False
    '    gv.AllowSorting = False
    '    gv.AutoGenerateColumns = False
    '    gv.AutoGenerateDeleteButton = False
    '    gv.AutoGenerateEditButton = False
    '    gv.AutoGenerateSelectButton = False
    '    gv.ClientIDMode = UI.ClientIDMode.Static
    '    gv.CssClass = "grid"
    '    gv.DataSource = Nothing
    '    gv.EmptyDataRowStyle.HorizontalAlign = HorizontalAlign.Center
    '    gv.EmptyDataText = "Aucun dossier"
    '    gv.ID = "gv" & code
    '    gv.ShowHeaderWhenEmpty = True

    '    gv.Columns.Add(InitializeBoundField("CodeDossier", "Code", , , HorizontalAlign.Center))
    '    gv.Columns.Add(InitializeBoundField("Identificateur", "Identificateur"))
    '    gv.Columns.Add(InitializeBoundField("DateFinValidite", "Fin de validité", , , HorizontalAlign.Center))
    '    gv.Columns.Add(InitializeBoundField("ListeActuelle", "Liste actuelle", , , HorizontalAlign.Center))
    '    gv.Columns.Add(InitializeBoundField("ListeSuivante", "Liste suivante", , , HorizontalAlign.Center))
    '    gv.Columns.Add(InitializeButtonsColumn())

    '    AddHandler gv.RowCommand, AddressOf gvDossier_RowCommand

    '    div.Controls.Add(gv)
    '    Me.tabs.Controls.Add(div)

    '    ' Ajout de l'en-tête de l'onglet
    '    li = New HtmlControls.HtmlGenericControl("li")
    '    a = New HtmlControls.HtmlAnchor()
    '    a.HRef = "#" & div.ClientID
    '    a.InnerText = text 'HttpUtility.HtmlEncode(text)
    '    li.Controls.Add(a)
    '    Me.tabs.Controls(0).Controls.Add(li)
    'End Sub
    'Private Function InitializeBoundField(field As String, text As String, Optional format As String = "", Optional headerAlign As HorizontalAlign = HorizontalAlign.Center, Optional itemAlign As HorizontalAlign = HorizontalAlign.Left) As BoundField
    '    Dim col As BoundField
    '    col = New BoundField()
    '    col.DataFormatString = format
    '    col.DataField = field
    '    col.HeaderStyle.HorizontalAlign = headerAlign
    '    col.HeaderText = text
    '    col.HtmlEncode = True
    '    col.ItemStyle.HorizontalAlign = itemAlign
    '    col.ReadOnly = True
    '    col.SortExpression = field
    '    Return col
    'End Function
    'Private Function InitializeButtonsColumn() As TemplateField
    '    Dim col As TemplateField

    '    ' Prise en charge des erreurs de lecture des assistants
    '    If ListeAssistants Is Nothing OrElse Not ListeAssistants.OK Then
    '        Me.tabs.InnerText = "Impossible de charger les assistants associés au type de dossier '" & TYPE_DOSSIER & "'" & If(ListeAssistants IsNot Nothing, " :" & ControlChars.NewLine & ListeAssistants.ErrorMessage, ".")
    '    End If

    '    col = New TemplateField()
    '    col.HeaderStyle.HorizontalAlign = HorizontalAlign.Right
    '    col.HeaderTemplate = New ButtonsGridViewTemplate(DataControlRowType.Header, ListeAssistants, "assemblée", True)
    '    col.ItemStyle.HorizontalAlign = HorizontalAlign.Right
    '    col.ItemTemplate = New ButtonsGridViewTemplate(DataControlRowType.DataRow, ListeAssistants, "assemblée", True)
    '    col.SortExpression = ""
    '    Return col
    'End Function

    'Private Sub Search()
    '    Me.ListesDossiers.Clear()

    '    If ListeEtats Is Nothing OrElse
    '       Not ListeEtats.OK OrElse
    '       ListeEtats.Liste.Count <= 0 Then Return

    '    ' Initialisation du service
    '    Using svc As New ServiceDeliberations.DeliberationsClient

    '        ' Initialisation des paramètres de recherche
    '        Dim params As New ServiceDeliberations.ParametresListeRapports
    '        params.Authentication = New ServiceDeliberations.AuthenticationParameters
    '        params.Authentication.Token = Tools.GetInstance.getToken

    '        ' Pour chaque état de dossier
    '        For Each item As ServiceParametre.OIItem In ListeEtats.Liste
    '            params.Etat = item.Code

    '            Try
    '                ' Recherche des dossiers et chargement du gridview associé
    '                Me.ListesDossiers.Add(item.Code, svc.ListeAssemblees(params))
    '            Catch ex As Exception
    '                Me.ListesDossiers.Add(item.Code, Nothing)
    '                NotifyErreur(ex.Message)
    '            End Try
    '        Next
    '    End Using
    'End Sub
    'Private Sub InitializeGridViews()
    '    If ListeEtats Is Nothing OrElse
    '       Not ListeEtats.OK OrElse
    '       ListeEtats.Liste.Count <= 0 Then Return

    '    ' Pour chaque état de dossier
    '    For Each item As ServiceParametre.OIItem In ListeEtats.Liste

    '        ' Prise en charge des erreurs de lecture des dossiers
    '        If ListesDossiers(item.Code) Is Nothing OrElse Not ListesDossiers(item.Code).OK Then
    '            NotifyErreur("Impossible de charger les dossiers de type '" & TYPE_DOSSIER & "' à l'état '" & item.Code & "'" & If(ListesDossiers(item.Code) IsNot Nothing, " :" & ControlChars.NewLine & ListesDossiers(item.Code).ErrorMessage, "."))
    '            Continue For
    '        End If

    '        ' Recherche du gridview associé
    '        Dim gv As GridView = CType(Odyssee.WebControles.Tools.FindControlOnPage(Me, "gv" & item.Code), GridView)
    '        If gv Is Nothing Then
    '            NotifyErreur("Impossible de trouver la liste associée à l'état de dossier '" & item.Libelle & "' (code : '" & item.Code & "').")
    '            Continue For
    '        End If

    '        gv.DataSource = ListesDossiers(item.Code).Rapports
    '        gv.DataBind()
    '    Next
    'End Sub

End Class